import { formatDate } from '@/utils/formatTime'
import { TableColumns } from '@pureadmin/table'
import { DICT_TYPE } from '@/utils/dict'
import DictTag from '@/components/DictTag/src/DictTag.vue'

interface TableColumnList extends Array<TableColumns> {}

export function useTable() {
  const columns: TableColumnList = [
    { prop: 'id', label: 'ID', minWidth: 80, align: 'center', fixed: 'left' },
    { prop: 'name', label: '商户名称', minWidth: 220, align: 'left', fixed: 'left', slot: 'name' },
    { prop: 'packageId', label: '商户套餐', minWidth: 80, align: 'center', slot: 'packageId' },
    {
      prop: 'tenantType',
      label: '商户类型',
      minWidth: 120,
      align: 'center',
      cellRenderer: ({ row }) => <DictTag type={DICT_TYPE.TENANT_IDENTITY} value={row.tenantType} />
    },
    { prop: 'contactName', label: '联系人', minWidth: 120, align: 'center' },
    { prop: 'contactMobile', label: '手机', minWidth: 120, align: 'center' },
    {
      prop: 'expireTime',
      label: '过期时间',
      minWidth: 180,
      align: 'center',
      formatter({ expireTime }) {
        return formatDate(expireTime)
      }
    },
    { prop: 'website', label: '绑定域名', minWidth: 180, align: 'center' },
    { prop: 'cropName', label: '来源', minWidth: 100, align: 'center' },
    {
      prop: 'status',
      label: '状态',
      minWidth: 100,
      align: 'center',
      cellRenderer: ({ row }) => <DictTag type={DICT_TYPE.COMMON_STATUS} value={row.status} />
    },
    {
      prop: 'createTime',
      label: '创建时间',
      minWidth: 180,
      align: 'center',
      formatter({ createTime }) {
        return formatDate(createTime)
      }
    },
    {
      label: '操作',
      fixed: 'right',
      minWidth: 248,
      align: 'center',
      slot: 'operation'
    }
  ]

  return {
    columns
  }
}
